package com.wd.visitor.common.controller;

import com.hq.dto.FicusResponse;
import com.hq.dto.FicusResponseSub;
import com.hq.dto.PutStaffResultDTO;
import com.wd.common.core.domain.HttpResponse;
import com.wd.common.exception.BusinessException;
import com.wd.visitor.common.domain.entity.Visitor;
import com.wd.visitor.common.service.VisitorService;
import com.wd.visitor.common.utils.ImageUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

/**
 * @className: VisitorController
 * @description: TODO 类描述
 * @author: liumingkun
 * @date: 2024/3/12
 **/

@RestController
public class VisitorController {

    private final static Logger logger = LoggerFactory.getLogger(VisitorController.class);

    @Resource
    VisitorService visitorService;

    @GetMapping("/hello")
    public HttpResponse hello() {

        return HttpResponse.success("This is hello API!");
    }

    @PostMapping("/visitor/add")
    public HttpResponse addVisitor(@RequestBody Visitor visitor) {
//        logger.info(visitor.toString());
//        try {
//            ImageUtils.uploadImage(visitor.getImg(),"/apps/img/");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        FicusResponseSub<List<FicusResponse<PutStaffResultDTO>>> listFicusResponseSub = visitorService.addVisitor(visitor);
        if(!listFicusResponseSub.message.equals("OK"))
        {
            return HttpResponse.error(listFicusResponseSub.result.get(0).message);
        }
        return HttpResponse.success();
    }

}
